package com.ruoyi.web.controller.system;

import java.util.Date;
import java.util.List;
import javax.servlet.http.HttpServletResponse;

import com.ruoyi.system.domain.dto.BanknoteSerialNumberRecordDto;
import com.ruoyi.system.domain.dto.MoneyRecordImportDto;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.system.domain.BanknoteSerialNumberRecord;
import com.ruoyi.system.service.IBanknoteSerialNumberRecordService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;
import org.springframework.web.multipart.MultipartFile;

/**
 * 冠字号记录Controller
 * 
 * @author ruoyi
 * @date 2025-02-27
 */
@RestController
@RequestMapping("/system/moneyRecord")
public class BanknoteSerialNumberRecordController extends BaseController
{
    @Autowired
    private IBanknoteSerialNumberRecordService banknoteSerialNumberRecordService;

    /**
     * 查询冠字号记录列表
     */
    @PreAuthorize("@ss.hasPermi('system:record:list')")
    @GetMapping("/list")
    public TableDataInfo list(BanknoteSerialNumberRecord banknoteSerialNumberRecord)
    {
//        startPage();
        List<BanknoteSerialNumberRecord> list = banknoteSerialNumberRecordService.selectBanknoteSerialNumberRecordList(banknoteSerialNumberRecord);
        return getDataTable(list);
    }

    /**
     * 导出冠字号记录列表
     */
    @PreAuthorize("@ss.hasPermi('system:record:export')")
    @Log(title = "冠字号记录", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, BanknoteSerialNumberRecord banknoteSerialNumberRecord)
    {
        List<BanknoteSerialNumberRecord> list = banknoteSerialNumberRecordService.selectBanknoteSerialNumberRecordList(banknoteSerialNumberRecord);
        ExcelUtil<BanknoteSerialNumberRecord> util = new ExcelUtil<BanknoteSerialNumberRecord>(BanknoteSerialNumberRecord.class);
        util.exportExcel(response, list, "冠字号记录数据");
    }

    /**
     * 导出冠字号记录列表
     */
    @PreAuthorize("@ss.hasPermi('system:record:add')")
    @Log(title = "冠字号记录", businessType = BusinessType.EXPORT)
    @PostMapping("/import")
    public void importExcel(@RequestParam("file") MultipartFile file) throws Exception {
        ExcelUtil<BanknoteSerialNumberRecordDto> util = new ExcelUtil<>(BanknoteSerialNumberRecordDto.class);
        List<BanknoteSerialNumberRecordDto> recordImportDtos = util.importExcel(file.getInputStream());
        banknoteSerialNumberRecordService.insertList(recordImportDtos);
    }

    /**
     * 获取冠字号记录详细信息
     */
    @PreAuthorize("@ss.hasPermi('system:record:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(banknoteSerialNumberRecordService.selectBanknoteSerialNumberRecordById(id));
    }

    /**
     * 新增冠字号记录
     */
    @PreAuthorize("@ss.hasPermi('system:record:add')")
    @Log(title = "冠字号记录", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody BanknoteSerialNumberRecord banknoteSerialNumberRecord)
    {
        return toAjax(banknoteSerialNumberRecordService.insertBanknoteSerialNumberRecord(banknoteSerialNumberRecord));
    }

    /**
     * 修改冠字号记录
     */
    @PreAuthorize("@ss.hasPermi('system:record:edit')")
    @Log(title = "冠字号记录", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody BanknoteSerialNumberRecord banknoteSerialNumberRecord)
    {
        return toAjax(banknoteSerialNumberRecordService.updateBanknoteSerialNumberRecord(banknoteSerialNumberRecord));
    }

    /**
     * 删除冠字号记录
     */
    @PreAuthorize("@ss.hasPermi('system:record:remove')")
    @Log(title = "冠字号记录", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(banknoteSerialNumberRecordService.deleteBanknoteSerialNumberRecordByIds(ids));
    }






}
